package com.huanqi.api;

import android.util.Log;

import androidx.annotation.NonNull;

import java.util.HashMap;

public enum ApiDouBanMap {

    标题 {
        public String message(String message) {
            return getMovieMessage(message, key(), value());
        }

        public String key() {
            return "<title>\n        ";
        }

        public String value() {
            return " (豆瓣)";
        }

        public String getmessage(String message) {
            return getMovieMessage(message, key(), value());
        }
    }, 副标题 {
        public String getmessage(String message) {
            return getMovieMessage(message, key(), value());
        }

        public String key() {
            return "<span property=\"v:itemreviewed\">";
        }

        public String value() {
            return "</span>";
        }
    }, 又名 {
        public String getmessage(String message) {

            return getMovieMessage(message, key(), value()).replace("/",",");
        }

        public String key() {
            return "<span class=\"pl\">又名:</span>";
        }

        public String value() {
            return "<br/>";
        }
    }, 导演 {
        public String getmessage(String message) {
            return getMovieMessage(message, key(), value()).replace("/",",");
        }

        public String key() {
            return "rel=\"v:directedBy\">";
        }

        public String value() {
            return "</a>";
        }
    }, 剧情 {
        public String getmessage(String message) {
            if (message.contains("<span property=\"v:summary\" class=\"\">")){
                return getMovieMessage(message, key2(), value());
            }else {
                return getMovieMessage(message, key(), value());
            }
        }

        public String key() {
            return "<span property=\"v:summary\">";
        }

        public String key2(){   return "<span property=\"v:summary\" class=\"\">";}

        public String value() {
            return "</span>";
        }
    }, 地区 {
        public String getmessage(String message) {
            return getMovieMessage(message, key(), value());
        }

        public String key() {
            return "<span class=\"pl\">制片国家/地区:</span>";
        }

        public String value() {
            return "<br/>";
        }
    }, 分类 {
        public String getmessage(String message) {
            return getMovieMessage(message, key(), value()).replace("/",",");
        }

        public String key() {
            return "<span class=\"pl\">类型:</span>";
        }

        public String value() {
            return "<br/>";
        }
    }, 年代 {
        public String getmessage(String message) {
            return getMovieMessage(message, key(), value());
        }

        public String key() {
            return "<span class=\"year\">(";
        }

        public String value() {
            return ")</span>";
        }
    }, 国家 {
        public String getmessage(String message) {
            return getMovieMessage(message, key(), value());
        }

        public String key() {
            return "<span class=\"pl\">制片国家/地区:</span>";
        }

        public String value() {
            return "<br/>";
        }
    }, 语言 {
        public String getmessage(String message) {
            return getMovieMessage(message, key(), value()).replace("/",",");
        }

        public String key() {
            return " <span class=\"pl\">语言:</span>";
        }

        public String value() {
            return "<br/>";
        }
    }, ID {
        public String getmessage(String message) {
            return getMovieMessage(message, key(), value());
        }

        public String key() {
            return "share-id=\"";
        }

        public String value() {
            return "\" \n";
        }
    }, 海报 {
        public String getmessage(String message) {
            return getMovieMessage(message, key(), value());
        }

        public String key() {
            return "title=\"点击看更多海报\">\n        <img src=\"";
        }

        public String value() {
            return "\" title=\"点击看更多海报\"";
        }
    }, 评分 {
        public String getmessage(String message) {
            return getMovieMessage(message, key(), value());
        }

        public String key() {
            return "property=\"v:average\">";
        }

        public String value() {
            return "</strong>";
        }
    }
    , 片长 {
        public String getmessage(String message) {
            if (message.contains("单集片长")){
                return getMovieMessageX(message, key2(), value());
            }else if (message.contains("片长")){
                return getMovieMessageX(getMovieMessageX(message, key(), value()), ">", "</span>");
            }
            return "";
        }

        public String key() {
            return "<span class=\"pl\">片长:</span>";
        }
        public String key2() {
            return "<span class=\"pl\">单集片长:</span>";
        }

        public String value() {
            return "<br/>";
        }
    },上映日期 {
        public String getmessage(String message) {
            String messagex="";
            String key = "";
            if (message.contains("上映日期")){
                key=key();
            }else if (message.contains("首播")){
                key=key2();
            }

            if (getMovieMessageX(message, key, value()).contains("an>/")) {
                String[] messages = getMovieMessageX(message, key(), value()).split("an>/");
                for (int i = 0; i < messages.length; i++) {
                    if (i==messages.length-1){
                        messagex +=getMovieMessageX(messages[i], "content=\"", "\">");
                    }else {
                        messagex +=getMovieMessageX(messages[i], "content=\"", "\">")+"/";
                    }
                }
            } else {
                messagex= getMovieMessageX(getMovieMessageX(message,key, value()), "content=\"", "\">");
            }
            return messagex.replace("/",",");
        }

        public String key() {
            return "<span class=\"pl\">上映日期:</span> ";
        }
        public String key2() {
            return "<span class=\"pl\">首播:</span> ";
        }

        public String value() {
            return "<br/>";
        }
    }, 演员 {
        public String getmessage(String message) {
            String messagex="";
            if (getMovieMessage(message, key(), value()).contains("a>/")) {
                String[] messages = getMovieMessage(message, key(), value()).split("a>/");
                for (int i = 0; i < messages.length; i++) {
                    if (i==messages.length-1){
                        messagex +=getMovieMessage(messages[i], "rel=\"v:starring\">", "</");
                    }else {
                        messagex +=getMovieMessage(messages[i], "rel=\"v:starring\">", "</")+"/";
                    }
                }
            } else {
                messagex= getMovieMessage(getMovieMessage(message, key(), value()), "rel=\"v:starring\">", "</a>");
            }
            return messagex.replace("/",",").replace("'","");
        }

        public String key() {
            return "<span class='pl'>主演</span>: <span class='attrs'>";
        }

        public String value() {
            return "</span></span><br/>";
        }
    };

    public abstract String key();

    public abstract String value();

    public abstract String getmessage(String message);

    public static String getMovieMessage(String message, String start, String end) {
        if (!message.contains(start) || !message.contains(end)) {
            return "";
        }
        return message.substring((message.indexOf(start) + (start).length()), message.indexOf(end, message.indexOf(start)))
                .replace("<span property=\"v:genre\">", "")
                .replace("</span>", "")
                .replace("<br />", "")
                .replace("\n", "")
                .replace("\r", "")
                .replace(" ", "")
                .replace("　　","")
                .trim();
    }

    public static String getMovieMessageX(String message, String start, String end) {//不删除span
        if (!message.contains(start) || !message.contains(end)) {
            return "";
        }
        return message.substring((message.indexOf(start) + (start).length()), message.indexOf(end, message.indexOf(start)))
                .replace("<br />", "")
                .replace("\n", "")
                .replace("\r", "")
                .replace(" ", "")
                .replace("　　","")
                .trim();
    }

}
